home *** CD-ROM | disk | FTP | other *** search
- /*
-
- License: This source code may not be used in other applications whether they
- be personal, commercial, free, or paid without written permission from Read It Later.
-
-
- /////////
- DEVELOPER API: readitlaterlist.com/api/
- /////////
-
- If you would like to customize Read It Later or build an application that works with
- Read it Later take a look at the READ IT LATER OPEN API:
- http://readitlaterlist.com/api/
-
- Suggestions for additions to Read It Later are VERY welcome. A large number of user
- suggestions have been implemented. Please let me know of any additional features you
- are seeking at: http://readitlaterlist.com/support/
-
- Thanks
-
- */
-
- Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-
- function RILtextDownloader() {
- this.type = 1;
- }
-
- // class definition
- RILtextDownloader.prototype = {
-
- // properties required for XPCOM registration:
- classDescription: "Read It Later Text Downloader Javascript XPCOM Component",
- classID: Components.ID("{378c38a0-abaa-11de-8a39-0800200c9a66}"),
- contractID: "@ril.ideashower.com/riltextdownloader;1",
-
- QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIRILtextDownloader]),
-
- //////////////////////////////////////////
-
- init : function(itemId, url, callback)
- {
- this.itemId = itemId;
- this.url = url;
- this.callback = callback ? callback : 'textFinished';
-
- this.APP = Components.classes['@ril.ideashower.com/rildelegate;1'].getService().wrappedJSObject;
- this.ASSETS = Components.classes['@ril.ideashower.com/rilassetmanager;1'].createInstance(Components.interfaces.nsIRILassetManager);
- this.ASSETS.init();
- this.JSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
- this.markupPath = this.ASSETS.folderPathForItemId( itemId ) + 'text.html';
-
- this.requestId = itemId + '-' + url + '-' + Math.random();
- return this.requestId;
- },
-
-
- // Run on the main thread because of ajax request
- start : function(threadId)
- {
- try
- {
- this.threadId = threadId;
- this.APP.SYNC.request( 'text', false, '&url='+this.url, this, 'textCallback', 'none');
- return;
- } catch(e){Components.utils.reportError(e);}
-
- //else
- this.finish(false);
- },
-
- // This is performed on the main thread
- textCallback : function(request, success, response)
- {
- try {
-
- if (this.finished) return false;
-
- this.title = request.header('X-Title');
-
- this.APP.d( 'status: ' + request.status );
- this.APP.d( 'X-Error: ' + request.error );
- this.APP.d( 'X-Title: ' + request.header('X-Title') );
-
- if (!request.success)
- {
- this.finish( false, request.status );
- this.error = request.error;
- }
- else
- {
-
- // Update stylesheet
- let markup = response;
-
- markup = markup.replace('<!--!ENDOFHEADSECTION-->', '<link type="text/css" rel="stylesheet" href="chrome://isreaditlater/content/text.css" /><script type="text/javascript" src="chrome://isreaditlater/content/text.js"></script>');
- markup = markup.replace('<!--!TOPOFCTN-->',
- '<div id="RIL_header">\
- <div id="RIL_top">\
- <cite>\
- <span>\
- <br /><br />Original: \
- </span>\
- <a href="'+this.url+'" target="_blank">'+this.url+'</a>\
- </cite>\
- <a class="i" id="RIL_settings"></a>\
- </div>\
- <div id="RIL_settings_wrapper"></div>\
- <br />\
- <h1>'+request.header('X-Title')+'</h1>\
- </div>\
- \
- <ul id="RIL_nav">\
- <li>Show:</li>\
- <li id="nav_less"><a>Less</a></li>\
- <li id="nav_more"><a>More</a></li>\
- </ul>\
- ');
-
- // -- Save text to file
-
- // Write file in thread
- this.APP.OFFLINE.write( this.markupPath, markup, false, this, 'finish');
-
- }
-
- } catch(e) {Components.utils.reportError(e);}
- },
-
- finish : function(success, statusCode)
- {
- this.finished = true;
- this.success = success;
- this.statusCode = statusCode ? statusCode : (success ? 1 : -1);
- this.APP.OFFLINE[this.callback].call(this.APP.OFFLINE, this);
- },
-
- cancel : function(soft)
- {
- //dump("\n -- cancelling.. ");
-
- this.finished = true;
-
- }
-
- };
-
- var components = [RILtextDownloader];
- function NSGetModule(compMgr, fileSpec) {
- return XPCOMUtils.generateModule(components);
- }
-